home *** CD-ROM | disk | FTP | other *** search
- //basic particle shader
- //rotates particles as they rise
- //input should be 4 points that are the same, tex coord will expand them in screen space
- //3rd component of tex coord is size of particle
- //Luke Lenhart
- //(C)2004-2005 Digipen Institute of Technology
-
- //view,projection transform
- float4x4 matViewProj;
-
- //camera position in world space
- float4 cameraPos;
-
- //base position of emitter
- //float3 basePos;
-
- //shader input
- struct VS_INPUT
- {
- float4 Pos : POSITION;
- float4 Color : COLOR;
- float3 Tex0 : TEXCOORD0;
- };
-
- //shader output
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float4 Color : COLOR;
- float2 Tex0 : TEXCOORD0;
- };
-
- //shader code
- VS_OUTPUT VShader(VS_INPUT In)
- {
- VS_OUTPUT Out;
-
- //transform pos and copy tex coord and color over
- Out.Pos=mul(matViewProj,In.Pos);
- Out.Tex0.xy=In.Tex0.xy;
- Out.Color=In.Color;
-
- float2 posOffset=In.Tex0-0.5f;
-
- //calc rotation matrix based on in component
- float theta=dot(In.Pos,float3(0.2f,0.2f,0.2f))+(2.0f + 1.0f / In.Pos.z)*4.0f;
- float2x2 matRot={cos(theta),sin(theta),-sin(theta),cos(theta)};
- posOffset=mul(matRot,posOffset);
-
- //expand outwards from center point, based on distance and tex coord
- float dist=distance(cameraPos.xyz,In.Pos.xyz);
-
- Out.Pos.xy+=(1.0f/sqrt(dist))*posOffset*In.Tex0.z;
-
- //spit out the results
- return Out;
- }
-